//
//  DAO.m
//  Aun
//
//  Created by Alexander on 8/24/10.
//  Copyright 2010 KTH Royal Institute of Technology. All rights reserved.
//

#import "DAO.h"
#import "User.h"
#import "Patient.h"
#import "MRExamination.h"

static DAO *INSTANCE;
static User *user;
static NSMutableArray *patients;

@implementation DAO

+ (void)initialize {
	INSTANCE = [[DAO alloc] init];
}

+ (DAO *)getInstance {
    return INSTANCE;
}

- (DAO *)init {
    self = [super init];
    if (self) {
        patients = [[NSMutableArray alloc] init];
		
		// create user
		user = [[User alloc] initWithIdentifier:[[NSString alloc] initWithFormat:@"u1"] name:@"Doc Holiday" username:@"doc" passhash:@"holiday"];
 
		// create some patients
		Patient *p = [[Patient alloc] initWithIdentifier:@"p1" 
													name:@"Helen of Troy" 
												username:@"helen" 
												passhash:@"p1" 
												   photo:[UIImage imageNamed:@"helenoftroy.jpg"] 
											  bubbleText:@"bla bla bubble for Helen" 
										  patientSummary:@"Patient summary for Helen here." 
							questionsForConsensusMeeting:@"Questions about Helen for consensus meeting here." 
									   previousDecisions:@"Previous Desicions regarding Helen here." 
							finishedAndOngoingTreatments:@"Finished and ongoing treatments for Helen here."];
		
		//MRExamination *e = [[MRExamination alloc] initWithMRImages:<#(NSArray *)mrImages#> report:@""];
		//[[p activities] insertObject:<#(id)anObject#> atIndex:<#(NSUInteger)index#>];
		
		
		[patients addObject:p];
		p = [[Patient alloc] initWithIdentifier:@"p2" 
										   name:@"Hector" 
									   username:@"hector" 
									   passhash:@"p2" 
										  photo:[UIImage imageNamed:@"sick_man.JPG"] 
									 bubbleText:@"bla bla bubble for Hector" 
								 patientSummary:@"Patient summary for Hector here." 
				   questionsForConsensusMeeting:@"Questions about Hector for consensus meeting here." 
							  previousDecisions:@"Previous Desicions regarding Hector here." 
				   finishedAndOngoingTreatments:@"Finished and ongoing treatments for Hector here."];
		[patients addObject:p];
	}
    return self;
}

- (User *)getUser {
    return user;
}

- (NSMutableArray *)getPatients {
    return patients;
}

/*- (Patient *)getPatientWithIdentifier:(NSString *)identifier {
    for (int i = 0; i < [patients count]; i++)
	    if ([[[patients objectAtIndex:i] identifier] isEqualToString:identifier])
			return [patients objectAtIndex:i];
	return nil;
}*/

@end
